home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
src
/
fig09_05.jar
/
Ch09
/
Fig09_05
/
Employ.cpp
next >
Wrap
C/C++ Source or Header
|
1997-10-26
|
953b
|
33 lines
// Fig. 9.5: employ.cpp
// Member function definitions for class Employee
#include <string.h>
#include <iostream.h>
#include <assert.h>
#include "employ.h"
// Constructor dynamically allocates space for the
// first and last name and uses strcpy to copy
// the first and last names into the object.
Employee::Employee( const char *first, const char *last )
{
firstName = new char[ strlen( first ) + 1 ];
assert( firstName != 0 ); // terminate if not allocated
strcpy( firstName, first );
lastName = new char[ strlen( last ) + 1 ];
assert( lastName != 0 ); // terminate if not allocated
strcpy( lastName, last );
}
// Output employee name
void Employee::print() const
{ cout << firstName << ' ' << lastName; }
// Destructor deallocates dynamically allocated memory
Employee::~Employee()
{
delete [] firstName; // reclaim dynamic memory
delete [] lastName; // reclaim dynamic memory
}